www.gusucode.com > 基于马尔科夫随机场的图像分割matlab源码。包括ICM迭代条件模式求解最大后验概率算法 > code23/matlab MRF toy examples/ICM.m

    %% ICM.m
% perform one sweep through the network of iterated conditional modes
%oct. 7, 2003  wtf created.

function [nodes] = ICM(nodes);

nStates = length(nodes{1}.marginal);
visitingOrder = randperm(length(nodes));
for iNode = visitingOrder
    probStates = zeros(nStates,1);
    for k = 1:nStates
        probStates(k) = getCliqueProb(nodes,iNode,k);
    end
    [yy, ii] = max(probStates);
    nodes{iNode}.state =  ii;
end